import 'dart:math';

import 'package:catguard/language.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../config/config.dart';
import '../../generated/assets.dart';
import '../../utils/count_down_time_util.dart';
import '../../utils/edit_focus_util.dart';
import '../../views/common_widget.dart';
import 'register_logic.dart';

class RegisterPage extends StatelessWidget {
  RegisterPage({super.key});

  final logic = Get.find<RegisterLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg2,
      body: InkWell(
        splashColor: Colors.transparent,
        highlightColor: Colors.transparent,
        onTap: () {
          FocusManager.instance.primaryFocus?.unfocus();
        },
        child: Stack(
          children: [
            SingleChildScrollView(
              child: Column(
                children: [
                  //appbar
                  CommonWidget.commonAppBar(''),
                  //logo
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Container(
                          margin: EdgeInsets.only(top: 15.w),
                          width: 200.w,
                          height: 200.w,
                          padding: EdgeInsets.all(2.w),
                          decoration: BoxDecoration(
                            color: Config.colorBg2.withOpacity(0.6),
                            borderRadius: BorderRadius.circular(50.w),
                          ),
                          child: ClipRRect(
                            borderRadius: BorderRadius.circular(50.w),
                            child: Image.asset(
                              Assets.imagesLauncher,
                            ),
                          )),
                    ],
                  ),
                  // //提示语
                  Container(
                      margin: EdgeInsets.only(top: 15.w),
                      padding: EdgeInsets.symmetric(horizontal: 60.w),
                      child: Column(
                        children: [
                          Text(
                            LanguageMsg.loginTips.tr,
                            textAlign: TextAlign.center,
                            style: TextStyle(
                                color: Config.colorText1,
                                fontSize: Config.textSizeSubTitle.sp,
                                height: 1.6),
                          ),
                        ],
                      )),
                  //中间
                  Container(
                    padding: EdgeInsets.only(top: 10.w, left: 60.w, right: 60.w, bottom: 20.w),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        //输入框1
                        Container(
                          margin: EdgeInsets.only(top: 40.w, bottom: 24.w),
                          alignment: Alignment.centerLeft,
                          child: Text(
                            LanguageMsg.userName.tr,
                            style: TextStyle(
                              color: Config.colorText1,
                              fontSize: Config.textSizeSubTitle.sp,
                            ),
                          ),
                        ),
                        CommonWidget.commonEditText(
                          false,
                          (value) {
                            //获得输入的内容
                            logic.userName.value = value;
                          },
                          () {
                            //输入框被点击了
                            EditFocusUtils.setFocus(logic.focusNode1);
                          },
                          () {
                            //右边图标被点击了
                          },
                          logic.focusNode1,
                          isRightIcon: false,
                          maxLength: 40,
                          contentPaddingV: 25.w,
                          hint: "login_input_email_tips".tr,
                          fillColor: Config.colorBg.withOpacity(0.88),
                          sideColorN: Config.colorText3.withOpacity(0.04),
                          sideColorP: Config.colorText1,
                          keyboardType: TextInputType.text,
                          fontSize: Config.textSizeContent.sp,
                        ),
                        Container(
                          margin: EdgeInsets.only(top: 40.w, bottom: 24.w),
                          alignment: Alignment.centerLeft,
                          child: Text(
                            LanguageMsg.loginTagPwd.tr,
                            style: TextStyle(
                              color: Config.colorText1,
                              fontSize: Config.textSizeSubTitle.sp,
                            ),
                          ),
                        ),
                        //输入框2
                        Obx(
                          () => CommonWidget.commonEditText(
                            logic.isHidePwd.value,
                            (value) {
                              //获得输入的内容
                              logic.passWord.value = value;
                            },
                            () {
                              //输入框被点击了
                              EditFocusUtils.setFocus(logic.focusNode2);
                            },
                            () {
                              //右边图标被点击了
                              logic.isHidePwd.value = !logic.isHidePwd.value;
                            },
                            logic.focusNode2,
                            isRightIcon: true,
                            contentPaddingV: 25.w,
                            rightIconRight: 25.w,
                            maxLength: 20,
                            hint: "login_input_pwd_tips".tr,
                            fillColor: Config.colorBg.withOpacity(0.88),
                            sideColorN: Config.colorText3.withOpacity(0.04),
                            sideColorP: Config.colorText1,
                            keyboardType: TextInputType.text,
                            fontSize: Config.textSizeContent.sp,
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(top: 40.w, bottom: 24.w),
                          alignment: Alignment.centerLeft,
                          child: Text(
                            LanguageMsg.generalVerificationCode.tr,
                            style: TextStyle(
                              color: Config.colorText1,
                              fontSize: Config.textSizeSubTitle.sp,
                            ),
                          ),
                        ),
                        //输入框3
                        CommonWidget.commonEditText(
                          false,
                          (value) {
                            //获得输入的内容
                            logic.inviteCode.value = value;
                          },
                          () {
                            //输入框被点击了
                            EditFocusUtils.setFocus(logic.focusNode3);
                          },
                          () {
                            //右边图标被点击了
                          },
                          logic.focusNode3,
                          isRightIcon: false,
                          maxLength: 6,
                          contentPaddingV: 25.w,
                          hint: LanguageMsg.generalInputVerificationTips.tr,
                          fillColor: Config.colorBg.withOpacity(0.88),
                          sideColorN: Config.colorText3.withOpacity(0.04),
                          sideColorP: Config.colorText1,
                          keyboardType: TextInputType.text,
                          fontSize: Config.textSizeContent.sp,
                          rightText: "获取验证码"
                        ),
                        SizedBox(height: 50.w),

                        GestureDetector(
                          onTap: () {
                            logic.register();
                          },
                          child: Container(
                            margin: EdgeInsets.fromLTRB(0.w, 30.w, 0.w, 0.w),
                            padding: EdgeInsets.symmetric(horizontal: 22.w),
                            height: 96.w,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.all(Radius.circular(58.w)),
                              border: Border.all(color: Config.colorText1,width: 3.w),
                              gradient: LinearGradient(
                                begin: Alignment.topCenter,
                                end: Alignment.bottomCenter,
                                colors: [Config.colorMain, Config.colorMain.withOpacity(0.9)],
                              ),
                            ),
                            child: Text(
                              "register_title".tr,
                              style: TextStyle(color: Config.colorText1, fontSize: 34.sp),
                            ),
                          ),
                        ),
                        //忘记密码和注册
                        Container(
                          margin: EdgeInsets.only(right: 50.w, top: 30.w, left: 50.w),
                          width: double.infinity,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              InkWell(
                                splashColor: Colors.transparent,
                                highlightColor: Colors.transparent,
                                onTap: () {
                                  // Get.toNamed(Routes.forgetPassword, arguments: {'isChange': false});
                                },
                                child: Container(
                                  alignment: Alignment.center,
                                  margin: EdgeInsets.only(top: 0.w, left: 70.w),
                                  child: Text(
                                    LanguageMsg.registerBottomLogin.tr,
                                    style: TextStyle(
                                        color: Config.colorText1,
                                        fontSize: Config.textSizeContent.sp),
                                  ),
                                ),
                              ),
                              Container(
                                margin: EdgeInsets.symmetric(horizontal: 12.w),
                                width: 3.w,
                                height: 26.w,
                                decoration: BoxDecoration(color: Config.colorDivider),
                              ),
                              InkWell(
                                splashColor: Colors.transparent,
                                highlightColor: Colors.transparent,
                                onTap: () {
                                  Get.back();
                                },
                                child: Container(
                                  alignment: Alignment.center,
                                  margin: EdgeInsets.only(top: 0.w, right: 70.w),
                                  child: Text(
                                    LanguageMsg.nowLogin.tr,
                                    style: TextStyle(
                                        color: Config.colorMain,
                                        fontSize: Config.textSizeContent.sp),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
